#pragma once
#include <QImage>
#include <QPainter>
#include "KinectLib.h"

// class KinectQtRender
class KinectQtRender
{
public:
    KinectQtRender();
    virtual ~KinectQtRender();

public:
    void setScaleRatio(float ratio);
    void drawColorToBitmap(KinectLib *pKinect, int width, int height, const KinectImageFrame &frame, bool drawSkeleton = false);
    void drawDepthToBitmap(KinectLib *pKinect, int width, int height, const KinectDepthFrame &frame, bool drawSkeleton = false);
    void setSkeletonFrame(const NUI_SKELETON_FRAME &frame);
    void drawSkeletonToBitmap(KinectLib *pKinect, int width, int height, const NUI_SKELETON_FRAME &frame);
    void drawSkeletonToGraphics(QPainter &painter, KinectLib *pKinect, int width, int height, const NUI_SKELETON_FRAME &frame);
    void drawPositionTextToBitmap(KinectLib *pKinect, int width, int height, const NUI_SKELETON_FRAME &frame);
    void drawPositionTextToGraphics(QPainter &painter, KinectLib *pKinect, int width, int height, const NUI_SKELETON_FRAME &frame);
    void drawAngleTextToBitmap(KinectLib *pKinect, int width, int height, const NUI_SKELETON_FRAME &frame);
    void drawAngleTextToGraphics(QPainter &painter, KinectLib *pKinect, int width, int height, const NUI_SKELETON_FRAME &frame);

    QImage *                    getColorBitmap();
    QImage *                    getDepthBitmap();
    QImage *                    getSkeletonBitmap();
    const NUI_SKELETON_FRAME &  getSkeletonFrame();

public:
    static bool saveImageToFile(QImage *image, const WCHAR *fileName);

private:
    void drawBone(QPainter &painter, const NUI_SKELETON_DATA & skeletonData, 
        const NUI_SKELETON_POSITION_INDEX joint0, const NUI_SKELETON_POSITION_INDEX joint1);
    void drawAngle(QPainter &painter, const NUI_SKELETON_DATA & skeletonData, 
        const NUI_SKELETON_POSITION_INDEX joint0,
        const NUI_SKELETON_POSITION_INDEX joint1, 
        const NUI_SKELETON_POSITION_INDEX joint2);

private:
    QImage *            mColorBitmap;
    QImage *            mDepthBitmap;
    QImage *            mDepthFrame;
    QImage *            mSkeletonBitmap;
    QPoint              mSkeletonPoints[NUI_SKELETON_POSITION_COUNT];
    SkeletonPoint       mSkeleton3Points[NUI_SKELETON_POSITION_COUNT];
    NUI_SKELETON_FRAME  mSkeletonFrame;

    QColor              mSkeletonBackColor;
    QColor              mTrackedLineColor;
    QColor              mInferredLineColor;
    QColor              mTrackedEllipseColor;
    QColor              mInferredEllipseColor;

    float               mLineWidth;
    float               mHeadDiameter;
    float               mHandFootDiameter;
    float               mJointDiameter;
    float               mScaleRatio;
    QPen *              mDrawPen;
    QBrush *            mDrawBrush;
    QFont *             mTextFont;
    QPen *              mTextPen;
};